<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Store Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset="utf-8">
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
    <script src="../js/lunr.min.js" defer></script>
    <script src="../js/typeahead.jquery.js" defer></script>
    <script src="../js/jazzy.search.js" defer></script>
  </head>
  <body>

    <a name="//apple_ref/swift/Class/Store" class="dashAnchor"></a>

    <a title="Store Class Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="../index.html">
          Katana 5.1.1 Docs
        </a>
         (99% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="../search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/BendingSpoons/katana-swift">
            <img class="header-icon" src="../img/gh.png"/>
            View on GitHub
          </a>
        </p>
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="../index.html">Katana Reference</a>
      <img class="carat" src="../img/carat.png" />
      Store Class Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/EmptySideEffectDependencyContainer.html">EmptySideEffectDependencyContainer</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/PartialStore.html">PartialStore</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/Store.html">Store</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/Store/Configuration.html">– Configuration</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/DispatchableLogger.html">DispatchableLogger</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Extensions/DispatchQueue.html">DispatchQueue</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/AnySideEffect.html">AnySideEffect</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/AnySideEffectContext.html">AnySideEffectContext</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/AnyStateUpdater.html">AnyStateUpdater</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/AnyStore.html">AnyStore</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/AsyncProvider.html">AsyncProvider</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/DispatchObserverDispatchable.html">DispatchObserverDispatchable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/Dispatchable.html">Dispatchable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/NotificationObserverDispatchable.html">NotificationObserverDispatchable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/OnStartObserverDispatchable.html">OnStartObserverDispatchable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/SideEffect.html">SideEffect</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/SideEffectDependencyContainer.html">SideEffectDependencyContainer</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/State.html">State</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/StateObserverDispatchable.html">StateObserverDispatchable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/StateUpdater.html">StateUpdater</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/ObserverInterceptor.html">ObserverInterceptor</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/ObserverInterceptor/ObserverType.html">– ObserverType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/SideEffectContext.html">SideEffectContext</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/SignpostLogger.html">SignpostLogger</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Typealiases.html">Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Typealiases.html#/s:6Katana11AnyDispatcha">AnyDispatch</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Typealiases.html#/s:6Katana16AnyStoreListenera">AnyStoreListener</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Typealiases.html#/s:6Katana8GetStatea">GetState</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Typealiases.html#/s:6Katana16StoreInterceptora">StoreInterceptor</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Typealiases.html#/s:6Katana20StoreInterceptorNexta">StoreInterceptorNext</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Typealiases.html#/s:6Katana13StoreListenera">StoreListener</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Typealiases.html#/s:6Katana16StoreUnsubscribea">StoreUnsubscribe</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content top-matter">
            <h1>Store</h1>
              <div class="declaration">
                <div class="language">
                  
                  <pre class="highlight swift"><code><span class="kd">open</span> <span class="kd">class</span> <span class="kt">Store</span><span class="o">&lt;</span><span class="kt">S</span><span class="p">,</span> <span class="kt">D</span><span class="o">&gt;</span> <span class="p">:</span> <span class="kt"><a href="../Classes/PartialStore.html">PartialStore</a></span><span class="o">&lt;</span><span class="kt">S</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">S</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/State.html">State</a></span><span class="p">,</span> <span class="kt">D</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/SideEffectDependencyContainer.html">SideEffectDependencyContainer</a></span></code></pre>

                </div>
              </div>
            <p>The <code>Store</code> is a sort of single entry point that handles the logic of your application.
In Katana, all the various pieces of information that your application manages should be stored
in a single atom, called state (see also <code><a href="../Protocols/State.html">State</a></code> protocol).</p>

<p>The <code>Store</code>, however, doesn&rsquo;t really implements any application specific logic: this class
only manages operations that are requested by the application-specific logic. In particular,
you can require the <code>Store</code> to execute something by <code>dispatching a dispatchable item</code>.</p>

<p>Currently the store handles 2 types of dispatchable: <code>State Updater</code>, <code>Side Effect</code></p>
<h4 id='update-the-state' class='heading'>Update the state</h4>

<p>As written before, in Katana every relevant information in the application should be stored in the
Store&rsquo;s state. The only way to update the state is to dispatch a <code><a href="../Protocols/StateUpdater.html">StateUpdater</a></code>.
At this point the <code>Store</code> will execute the following operations:</p>

<ul>
<li>it executes the interceptors</li>
<li>it creates the new state, by invoking the <code>updateState</code> function of the <code><a href="../Protocols/StateUpdater.html">StateUpdater</a></code></li>
<li>it updates the state</li>
<li>it resolves the promise</li>
</ul>
<h4 id='handle-to-business-logic' class='heading'>Handle to Business Logic</h4>

<p>Non trivial applications require to interact with external services and/or implement complex logics.
The proper way to handle these is by dispatching a <code><a href="../Protocols/SideEffect.html">SideEffect</a></code>.
The <code>Store</code> will execute the following operations:</p>

<ul>
<li>it executes the interceptors</li>
<li>it executes the <code><a href="../Protocols/SideEffect.html">SideEffect</a></code> body</li>
<li>it resolves the promise</li>
</ul>
<h4 id='listen-for-updates' class='heading'>Listen for updates</h4>

<p>You can attach a listener that is invoked every time the state changes by using <code>addListener</code>.</p>
<h4 id='intercept-dispatchable' class='heading'>Intercept Dispatchable</h4>

<p>It is possible to intercept and reshape the behaviour of the <code>Store</code> by using a <code><a href="../Typealiases.html#/s:6Katana16StoreInterceptora">StoreInterceptor</a></code>.
A <code><a href="../Typealiases.html#/s:6Katana16StoreInterceptora">StoreInterceptor</a></code> is executed every time something has dispatched, and before it is actually
managed by the <code>Store</code>. Here you implement behaviours like logging, blocking items before they&rsquo;re executed
and even change dynamically which dispatchable items arrive to the <code>Store</code> itself.</p>
<div class="aside aside-see-also">
    <p class="aside-title">See also</p>
    <code><a href="../Protocols/StateUpdater.html">StateUpdater</a></code> for more information about how to implement an update of the state

</div><div class="aside aside-see-also">
    <p class="aside-title">See also</p>
    <code><a href="../Protocols/SideEffect.html">SideEffect</a></code> for more information about how to implement a complex/asynchronous logic

</div>

              <div class="slightly-smaller">
                <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L211-L559">Show on GitHub</a>
              </div>
          </div>
        </section>

        <section class="section">
          <div class="section-content">
            <div class="task-group">
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC23DependenciesInitializera"></a>
                    <a name="//apple_ref/swift/Alias/DependenciesInitializer" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC23DependenciesInitializera">DependenciesInitializer</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Closure that is used to initialize the dependencies</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">DependenciesInitializer</span> <span class="o">=</span> <span class="p">(</span><span class="n">_</span> <span class="nv">dispatch</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt"><a href="../Typealiases.html#/s:6Katana11AnyDispatcha">AnyDispatch</a></span><span class="p">,</span> <span class="n">_</span> <span class="nv">getState</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt">StateInitializer</span><span class="o">&lt;</span><span class="kt">S</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">D</span></code></pre>

                        </div>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L213">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC7isReadySbvp"></a>
                    <a name="//apple_ref/swift/Property/isReady" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC7isReadySbvp">isReady</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Whether the store is ready to execute operations</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">private(set)</span> <span class="k">var</span> <span class="nv">isReady</span><span class="p">:</span> <span class="kt">Bool</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                        </div>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L227">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC12dependenciesq_Sgvp"></a>
                    <a name="//apple_ref/swift/Property/dependencies" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC12dependenciesq_Sgvp">dependencies</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The dependencies used in the side effects</p>
<div class="aside aside-see-also">
    <p class="aside-title">See also</p>
    <code><a href="../Protocols/SideEffect.html">SideEffect</a></code>

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">dependencies</span><span class="p">:</span> <span class="kt">D</span><span class="o">!</span></code></pre>

                        </div>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L232">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreCACyxq_Gycfc"></a>
                    <a name="//apple_ref/swift/Method/init()" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreCACyxq_Gycfc">init()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A convenience init method. The store won&rsquo;t have middleware nor dependencies for the side effects.
The state will be created using the default init of the state</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">convenience</span> <span class="nf">init</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>An instance of store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L271-L273">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC12interceptorsACyxq_GSayyAA12Dispatchable_pKcyAaF_pKccAA20AnySideEffectContext_pcG_tcfc"></a>
                    <a name="//apple_ref/swift/Method/init(interceptors:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC12interceptorsACyxq_GSayyAA12Dispatchable_pKcyAaF_pKccAA20AnySideEffectContext_pcG_tcfc">init(interceptors:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A convenience init method for the Store. The initial state will be created using the default
init of the state type.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">convenience</span> <span class="nf">init</span><span class="p">(</span><span class="nv">interceptors</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Typealiases.html#/s:6Katana16StoreInterceptora">StoreInterceptor</a></span><span class="p">])</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>interceptors</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>a list of interceptors that are executed every time something is dispatched</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>An instance of the store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L282-L287">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC12interceptors16stateInitializer13configurationACyxq_GSayyAA12Dispatchable_pKcyAaH_pKccAA20AnySideEffectContext_pcG_xycAC13ConfigurationVyxq__Gtcfc"></a>
                    <a name="//apple_ref/swift/Method/init(interceptors:stateInitializer:configuration:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC12interceptors16stateInitializer13configurationACyxq_GSayyAA12Dispatchable_pKcyAaH_pKccAA20AnySideEffectContext_pcG_xycAC13ConfigurationVyxq__Gtcfc">init(interceptors:<wbr>stateInitializer:<wbr>configuration:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A convenience init method for the Store. The dependencies will be created using the default init of the dependency type.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">convenience</span> <span class="nf">init</span><span class="p">(</span>
  <span class="nv">interceptors</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Typealiases.html#/s:6Katana16StoreInterceptora">StoreInterceptor</a></span><span class="p">],</span>
  <span class="nv">stateInitializer</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt">StateInitializer</span><span class="o">&lt;</span><span class="kt">S</span><span class="o">&gt;</span><span class="p">,</span>
  <span class="nv">configuration</span><span class="p">:</span> <span class="kt"><a href="../Classes/Store/Configuration.html">Configuration</a></span> <span class="o">=</span> <span class="o">.</span><span class="nf">init</span><span class="p">()</span>
<span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>interceptors</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>a list of interceptors that are executed every time something is dispatched</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>stateInitializer</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>a closure invoked to define the first state&rsquo;s value</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>configuration</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the configuration needed by the store to start properly</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>An instance of the store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L297-L308">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC12interceptors16stateInitializer012dependenciesE013configurationACyxq_GSayyAA12Dispatchable_pKcyAaI_pKccAA20AnySideEffectContext_pcG_xycq_5Hydra7PromiseCyypGAaI_pc_xyctcAC13ConfigurationVyxq__Gtcfc"></a>
                    <a name="//apple_ref/swift/Method/init(interceptors:stateInitializer:dependenciesInitializer:configuration:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC12interceptors16stateInitializer012dependenciesE013configurationACyxq_GSayyAA12Dispatchable_pKcyAaI_pKccAA20AnySideEffectContext_pcG_xycq_5Hydra7PromiseCyypGAaI_pc_xyctcAC13ConfigurationVyxq__Gtcfc">init(interceptors:<wbr>stateInitializer:<wbr>dependenciesInitializer:<wbr>configuration:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The default init method for the Store.</p>
<h4 id='initial-phases' class='heading'>Initial phases</h4>

<p>When the store is created, it doesn&rsquo;t immediately start to handle dispatched items.
Before that, in fact, the <code>Store</code> will (in order)</p>

<ul>
<li>create the dependencies</li>
<li>create the first state version by using the given <code>stateInitializer</code></li>
<li>initialise the interceptors</li>
</ul>

<p>Accessing the state before the <code>Store</code> is ready will lead to a crash of the application, as the
state of the system is not well defined. You can check whether the <code>Store</code> is ready by leveraging the <code><a href="../Classes/Store.html#/s:6Katana5StoreC7isReadySbvp">isReady</a></code> property.</p>

<p>A good practice in case you have to interact with the <code>Store</code> (e.g., get the state) in the initial phases of your
application is to dispatch a <code><a href="../Protocols/SideEffect.html">SideEffect</a></code>. When dispatching something, in fact, the <code>Store</code> guarantees that
items are managed only after that the <code>Store</code> is ready. Items dispatched during the initialization are suspended
and resumed as soon as the <code>Store</code> is ready.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span>
  <span class="nv">interceptors</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Typealiases.html#/s:6Katana16StoreInterceptora">StoreInterceptor</a></span><span class="p">],</span>
  <span class="nv">stateInitializer</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt">StateInitializer</span><span class="o">&lt;</span><span class="kt">S</span><span class="o">&gt;</span><span class="p">,</span>
  <span class="nv">dependenciesInitializer</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt"><a href="../Classes/Store.html#/s:6Katana5StoreC23DependenciesInitializera">DependenciesInitializer</a></span><span class="p">,</span>
  <span class="nv">configuration</span><span class="p">:</span> <span class="kt"><a href="../Classes/Store/Configuration.html">Configuration</a></span> <span class="o">=</span> <span class="o">.</span><span class="nf">init</span><span class="p">()</span>
<span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>interceptors</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>a list of interceptors that are executed every time something is dispatched</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>stateInitializer</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>a closure invoked to define the first state&rsquo;s value</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>dependenciesInitializer</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>a closure invoked to instantiate the dependencies</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>configuration</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the configuration needed by the store to start properly</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>An instance of store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L334-L363">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC14addAnyListeneryyycyAA5State_p_AaE_ptcF"></a>
                    <a name="//apple_ref/swift/Method/addAnyListener(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC14addAnyListeneryyycyAA5State_p_AaE_ptcF">addAnyListener(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds a listener to the store. A listener is basically a closure that is invoked
every time the Store&rsquo;s state changes. The listener is always invoked in the main queue</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="k">override</span> <span class="kd">public</span> <span class="kd">func</span> <span class="nf">addAnyListener</span><span class="p">(</span><span class="n">_</span> <span class="nv">listener</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt"><a href="../Typealiases.html#/s:6Katana16AnyStoreListenera">AnyStoreListener</a></span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt"><a href="../Typealiases.html#/s:6Katana16StoreUnsubscribea">StoreUnsubscribe</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>listener</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the listener closure</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>a closure that can be used to remove the listener</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L386-L390">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC11addListeneryyycyx_xtcF"></a>
                    <a name="//apple_ref/swift/Method/addListener(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC11addListeneryyycyx_xtcF">addListener(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds a typed listener to the store. A listener is basically a closure that is invoked
every time the Store&rsquo;s state changes</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="k">override</span> <span class="kd">public</span> <span class="kd">func</span> <span class="nf">addListener</span><span class="p">(</span><span class="n">_</span> <span class="nv">listener</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt"><a href="../Typealiases.html#/s:6Katana13StoreListenera">StoreListener</a></span><span class="o">&lt;</span><span class="kt">S</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt"><a href="../Typealiases.html#/s:6Katana16StoreUnsubscribea">StoreUnsubscribe</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>listener</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the listener closure</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>a closure that can be used to remove the listener</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L399-L406">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC8dispatchy5Hydra7PromiseCy11ReturnValueQyd__Gqd__AA19ReturningSideEffectRd__lF"></a>
                    <a name="//apple_ref/swift/Method/dispatch(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC8dispatchy5Hydra7PromiseCy11ReturnValueQyd__Gqd__AA19ReturningSideEffectRd__lF">dispatch(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Dispatches a <code><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></code> item</p>
<h4 id='threading' class='heading'>Threading</h4>

<p>The <code>Store</code> follows strict rules about the parallelism with which dispatched items are handled.
At the same time, it tries to leverages as much as possible the modern multi-core systems that our
devices offer.</p>

<p>When a <code><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></code> is dispatched, Katana will handle them in a parallel queue. A <code><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></code> is executed
and considered done when its body finishes to be executed. This means that side effects are not guaranteed to be run in
isolation, and you should take into account the fact that multiple side effects can run at the same time. This decision has
been taken to greatly improve the performances of the system. Overall, this should not be a problem as you cannot really change
the state of the system (that is, the store&rsquo;s state) without dispatching a <code><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></code>.</p>
<h4 id='promise-resolution' class='heading'>Promise Resolution</h4>

<p>When it comes to <code><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></code>s, the promise is resolved when the body of the <code><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></code> is executed
entirely (see <code><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></code> documentation for more information).</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="k">override</span> <span class="kd">public</span> <span class="kd">func</span> <span class="n">dispatch</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">dispatchable</span><span class="p">:</span> <span class="kt">T</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Promise</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">.</span><span class="kt">ReturnValue</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/ReturningSideEffect.html">ReturningSideEffect</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>dispatchable</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the side effect to dispatch</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>a promise parameterized to SideEffect&rsquo;s return value, that is resolved when the SideEffect is handled by the store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L432-L434">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC8dispatchy5Hydra7PromiseCyytGqd__AA13AnySideEffectRd__lF"></a>
                    <a name="//apple_ref/swift/Method/dispatch(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC8dispatchy5Hydra7PromiseCyytGqd__AA13AnySideEffectRd__lF">dispatch(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Dispatches a <code><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></code> item</p>
<h4 id='threading' class='heading'>Threading</h4>

<p>The <code>Store</code> follows strict rules about the parallelism with which dispatched items are handled.
At the same time, it tries to leverages as much as possible the modern multi-core systems that our
devices offer.</p>

<p>When a <code><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></code> is dispatched, Katana will handle them in a parallel queue. A <code><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></code> is executed and considered
done when its body finishes to be executed. This means that side effects are not guaranteed to be run in isolation, and you
should take into account the fact that multiple side effects can run at the same time. This decision has been taken to greatly
improve the performances of the system. Overall, this should not be a problem as you cannot really change
the state of the system (that is, the store&rsquo;s state) without dispatching a <code><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></code>.</p>
<h4 id='promise-resolution' class='heading'>Promise Resolution</h4>

<p>When it comes to <code><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></code>s, the promise is resolved when the body of the <code><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></code> is executed entirely (see
<code><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></code> documentation for more information).</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="k">override</span> <span class="kd">public</span> <span class="kd">func</span> <span class="n">dispatch</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">dispatchable</span><span class="p">:</span> <span class="kt">T</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Promise</span><span class="o">&lt;</span><span class="kt">Void</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/AnySideEffect.html">AnySideEffect</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>dispatchable</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the side effect to dispatch</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>a promise parameterized to SideEffect&rsquo;s return value, that is resolved when the SideEffect is handled by the store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L460-L462">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC8dispatchy5Hydra7PromiseCyytGqd__AA15AnyStateUpdaterRd__lF"></a>
                    <a name="//apple_ref/swift/Method/dispatch(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC8dispatchy5Hydra7PromiseCyytGqd__AA15AnyStateUpdaterRd__lF">dispatch(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Dispatches a <code><a href="../Protocols/Dispatchable.html">Dispatchable</a></code> item</p>
<h4 id='threading' class='heading'>Threading</h4>

<p>The <code>Store</code> follows strict rules about the parallelism with which dispatched items are handled.
At the same time, it tries to leverages as much as possible the modern multi-core systems that our
devices offer.</p>

<p>When an <code><a href="../Protocols/AnyStateUpdater.html">AnyStateUpdater</a></code> is dispatched, the Store enqueues it in a serial and synchronous queue. This means that the Store
executes one update of the state at the time, following the order in which it has received them. This is done
to guarantee the predictability of the changes to the state and avoid any race condition. In general, using a synchronous
queue is never a big problem as any operation that goes in an <code><a href="../Protocols/AnyStateUpdater.html">AnyStateUpdater</a></code> is very lightweight.</p>
<h4 id='promise-resolution' class='heading'>Promise Resolution</h4>

<p>When it comes to <code><a href="../Protocols/AnyStateUpdater.html">AnyStateUpdater</a></code>, the promise is resolved when the state is updated.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="k">override</span> <span class="kd">public</span> <span class="kd">func</span> <span class="n">dispatch</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">dispatchable</span><span class="p">:</span> <span class="kt">T</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Promise</span><span class="o">&lt;</span><span class="kt">Void</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/AnyStateUpdater.html">AnyStateUpdater</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>dispatchable</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the state updater to dispatch</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>a promise parameterized to void that is resolved when the state updater is handled by the store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L486-L488">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC11anyDispatchy5Hydra7PromiseCyypGAA12Dispatchable_pF"></a>
                    <a name="//apple_ref/swift/Method/anyDispatch(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC11anyDispatchy5Hydra7PromiseCyypGAA12Dispatchable_pF">anyDispatch(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Dispatches a <code><a href="../Protocols/Dispatchable.html">Dispatchable</a></code> item</p>
<h4 id='threading' class='heading'>Threading</h4>

<p>The <code>Store</code> follows strict rules about the parallelism with which dispatched items are handled.
At the same time, it tries to leverages as much as possible the modern multi-core systems that our
devices offer.</p>

<p>When a <code><a href="../Protocols/StateUpdater.html">StateUpdater</a></code> is dispatched, the Store enqueues it in a serial and synchronous queue. This means that the Store
executes one update of the state at the time, following the order in which it has received them. This is done
to guarantee the predictability of the changes to the state and avoid any race condition. In general, using a synchronous
queue is never a big problem as any operation that goes in a <code><a href="../Protocols/StateUpdater.html">StateUpdater</a></code> is very lightweight.</p>

<p>When it comes to <code><a href="../Protocols/SideEffect.html">SideEffect</a></code> items, Katana will handle them in a parallel queue. A <code><a href="../Protocols/SideEffect.html">SideEffect</a></code> is executed and considered
done when its body finishes to be executed. This means that side effects are not guaranteed to be run in isolation, and you
should take into account the fact that multiple side effects can run at the same time. This decision has been taken to greatly
improve the performances of the system. Overall, this should not be a problem as you cannot really change
the state of the system (that is, the store&rsquo;s state) without dispatching a <code><a href="../Protocols/StateUpdater.html">StateUpdater</a></code>.</p>
<h4 id='promise-resolution' class='heading'>Promise Resolution</h4>

<p>When it comes to <code><a href="../Protocols/StateUpdater.html">StateUpdater</a></code>, the promise is resolved when the state is updated. For <code><a href="../Protocols/SideEffect.html">SideEffect</a></code>,
the promise is resolved when the body of the <code><a href="../Protocols/SideEffect.html">SideEffect</a></code> is executed entirely (see <code><a href="../Protocols/SideEffect.html">SideEffect</a></code> documentation for
more information).</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="k">override</span> <span class="kd">public</span> <span class="kd">func</span> <span class="nf">anyDispatch</span><span class="p">(</span><span class="n">_</span> <span class="nv">dispatchable</span><span class="p">:</span> <span class="kt"><a href="../Protocols/Dispatchable.html">Dispatchable</a></span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Promise</span><span class="o">&lt;</span><span class="kt">Any</span><span class="o">&gt;</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>dispatchable</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the dispatchable to dispatch, it can be either a StateUpdater or a SideEffect</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>a promise that is resolved when the dispatchable is handled by the store</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L520-L532">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Katana5StoreC13ConfigurationV"></a>
                    <a name="//apple_ref/swift/Struct/Configuration" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Katana5StoreC13ConfigurationV">Configuration</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The dependencies used to initialize katana</p>

                        <a href="../Classes/Store/Configuration.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">Configuration</span></code></pre>

                        </div>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/blob/master//Sources/Store.swift#L544-L558">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </section>

      </article>
    </div>
    <section class="footer">
      <p>&copy; 2021 <a class="link" href="http://bendingspoons.com" target="_blank" rel="external">Bending Spoons Team</a>. All rights reserved. (Last updated: 2021-04-29)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
